import { createRouter, createWebHistory, createWebHashHistory } from 'vue-router'
import Layout from '@/layout/index.vue'

export const LAYOUT = () => Promise.resolve(Layout)

const router = createRouter({
  history: createWebHashHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '',
      component: LAYOUT,
      redirect: '/home',
      children: [
        {
          path: '/home',
          name: 'home',
          component: () => import('@/views/HomeView.vue'),
          meta: {
            title: 'Home'
          }
        },
        {
          path: '/overview',
          name: 'overview',
          component: () => import('@/views/OverviewView.vue'),
          meta: {
            title: 'Overview'
          }
        },
        {
          path: '/overviewlist',
          name: 'OverviewList',
          component: () => import('@/views/OverviewListView.vue'),
          meta: {
            title: 'Overview List'
          }
        },
        {
          path: '/browser',
          name: 'browser',
          component: () => import('@/views/BrowserView.vue'),
          meta: {
            title: 'Browser'
          }
        },
        {
          path: '/contact',
          name: 'contact',
          component: () => import('@/views/ContactView.vue'),
          meta: {
            title: 'Contact'
          }
        },
        {
          path: '/about',
          name: 'about',
          component: () => import('@/views/AboutView.vue'),
          meta: {
            title: 'COVID19'
          }
        }
      ]
    },
    {
      path: '/:pathMatch(.*)*',
      component: () => import('@/views/error/404.vue')
    }
  ],
})

router.beforeEach((to, from, next) => {
  document.title = to.meta.title ? `${to.meta.title} - OneCMS` : `OneCMS`
  next()
})

export default router
